package io.github.siltal.examsystembackend.dto;

import io.github.siltal.examsystembackend.entity.User;

public record RegisterResponse(Boolean ok, Long id,
                               String username,
                               String email,
                               String error) {
    public static RegisterResponse UsernameOrPasswordCantBeEmpty() {
        return new RegisterResponse(false, -1L, "", "", "用户名或密码不能为空");
    }

    public static RegisterResponse UsernameLengthError() {
        return new RegisterResponse(false, -1L, "", "", "用户名应当在5到16个字符之间");
    }

    public static RegisterResponse PasswordLengthError() {
        return new RegisterResponse(false, -1L, "", "", "密码应当在8到20个字符之间");
    }

    public static RegisterResponse usernameConflict() {
        return new RegisterResponse(false, -1L, "", "", "用户名重复");
    }

    public static RegisterResponse from(User user) {
        return new RegisterResponse(true, user.getId(), user.getUsername(), user.getEmail(), "");
    }


}